SUBROUTINE solve_helmholts(a_helm,b_helm,cm_helm,threshold, pi, &
                       idep, jdep,         &
                       ids,ide,jds,jde,kds,kde,   &
                       ims,ime,jms,jme,kms,kme,   &
                       its,ite,jts,jte,kts,kte,myprcid)

  IMPLICIT NONE

  INTEGER   ::           ims,ime,jms,jme,kms,kme,   &
                         ids,ide,jds,jde,kds,kde,   &
                         its,ite,jts,jte,kts,kte,   &
                         idep, jdep

  REAL*8,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(inout) :: pi
  REAL*8,DIMENSION(ims:ime,kms:kme,jms:jme):: x
!local
  REAL*4                               :: ep, threshold
  REAL*8                               :: d
  INTEGER,parameter                              :: iter_max=10
  INTEGER                              :: int1,int2
  INTEGER                              :: i,j,k,n,l,kk, myprcid
  INTEGER                              ::  ibegin,iend,jbegin,jend
  REAL,   DIMENSION(1:19,its:ite,kts-1:kte+1,jts:jte) ::   a_helm
  REAL,   DIMENSION(its:ite,kts-1:kte+1,jts:jte)  ::   b_helm
  !REAL,   DIMENSION(its:ite,kts-1:kte+1,jts:jte,0:iter_max)  ::   ap
  !REAL,   DIMENSION(its-1:ite+1,kts-1:kte+1,jts-1:jte+1,0:iter_max)  ::   p
  REAL,   DIMENSION(ims:ime,kms:kme,jms:jme,1:7) ::   cm_helm
#ifdef GPTL_TIMING
   integer   :: ret
    ret=GPTLsetoption (GPTLoverhead, 0); 
   ! ret=GPTLsetoption (GPTLdepthlimit , 2);
   !ret = gptlsetoption(gptlabort_on_error, 1)
   !ret = gptlsetutr(GPTLmpiwtime)
   ret = gptlinitialize()
   ret = gptlstart('gcr_main')
#endif

  ibegin = its
  iend   = ite
  jbegin = jts
  jend   = min (jde-1,jte)


  d=1.0d0
  ep=threshold
!    call system_clock(int1)
!    write(*,*) 'int1: ', int1
DO i=1,1
  CALL psolve_gcr_main(ep,a_helm,b_helm,cm_helm,iter_max,pi,d, &
                       idep, jdep,         &
                       ids,ide,jds,jde,kds,kde,   &
                       ims,ime,jms,jme,kms,kme,   &
                       its,ite,jts,jte,kts,kte,myprcid)
enddo
#ifdef GPTL_TIMING
   ret = gptlstop('gcr_main')
   ret = gptlpr_file("outfile_f90")
   !ret = GPTLpr_file ("outfile_f90");
   !ret = gptlpr(myprcid)
#endif


#ifdef GPTL_TIMING
   ret = gptlfinalize()
 !  WRITE(0,*) 'GRAPES-MODEL finished.'
#endif

 !    call system_clock(int2)
!    write(*,*) '(int2-int1)/1000. is ' , (int2-int1)/1000.
END SUBROUTINE solve_helmholts